package com.zhbg.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhbg.mapper.UserMapper;
import com.zhbg.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.UUID;

@Service
public class UserServiceImpl implements UserService{//用户信息加工
    @Autowired
    private UserMapper userMapper;
    @Override
    public String login(User user) {
        String password = user.getPassword();//用户输入的明文
        String md5pass = DigestUtils.md5DigestAsHex(password.getBytes());//密码加密
        user.setPassword(md5pass);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>(user);
        User userDB = userMapper.selectOne(queryWrapper);//提交用户信息
        if(userDB==null){
            return null;
        }
        String token = UUID.randomUUID().toString()
                .replace("-", "");
        return token;
    }
}
